<?php
declare(strict_types=1);

namespace Hyperfx\Utils;

class PageUtil
{
    private int $pageSize;
    private string $pageToken;
    public function __construct($request)
    {
        $this->pageToken  = $request->getPageToken();
        $this->pageSize = $request->getPageSize();
    }

    /**
     * 当前页
     */
    public function getPage(): int {
        return (int) $this->pageToken ?: 1;
    }

    /**
     * 每页数量
     */
    public function getPerPage(): int {
        return (int) $this->pageSize ?: 20;
    }

    /**
     * 获取 next_page_token
     */
    public function getNextPageToken(): string {
        return (string) ($this->getPage() + 1);
    }
}